package com.ghsc.ghxc.jsb.ui.live.fragment

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.live.bean.LiveSendRedResult
import com.ghsc.ghxc.jsb.ui.live.bean.ReceiveResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.live.fragment
 * 类名：LiveRedViewModel
 * 创建时间：2024/5/23 18:08
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class LiveRedViewModel : BaseViewModel() {

    /** 获取发红包所需参数 **/
    var onRedIndexData = MutableLiveData<BaseResponse<ReceiveResult>>()
    fun onRedIndexDataMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onSendPacketInfoData(paras) }
            executeResponse(
                response,
                { onRedIndexData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }
    /** 发送红包  **/
    val onSendPacketSubmitData: MutableLiveData<BaseResponse<LiveSendRedResult>> = MutableLiveData()
    fun onSendPacketSubmitMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onLiveSendPacketSubmitData(paras) }
            executeResponse(
                response,
                { onSendPacketSubmitData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }
}